package com.app.newcsc.fragment.my.exchangepoints.exchangepointsrecord;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.app.newcsc.BR;
import com.app.newcsc.R;
import com.app.newcsc.databinding.FragmentExchangepointsRecordBinding;
import com.app.newcsc.fragment.BaseFragmentPagerAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.base.BaseViewModel;

/**
 * @author: woking
 * @date: 2021/6/10
 * @description：
 */
public class ExchangePointsRecordFragment extends BaseFragment<FragmentExchangepointsRecordBinding, BaseViewModel> {

    private List<Fragment> mFragments;
    private List<String> titlePager;

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_exchangepoints_record;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        binding.ivTitleBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });

        mFragments = pagerFragment();
        titlePager = pagerTitleString();
        //设置Adapter
        BaseFragmentPagerAdapter pagerAdapter = new BaseFragmentPagerAdapter(getChildFragmentManager(), mFragments, titlePager);
        binding.viewPager.setAdapter(pagerAdapter);
        binding.viewPager.setOffscreenPageLimit(2);
        binding.tabs.setupWithViewPager(binding.viewPager);
        binding.viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabs));

        binding.ivTitleBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });
    }

    @Override
    public void initViewObservable() {

    }

    protected List<Fragment> pagerFragment() {
        List<Fragment> list = new ArrayList<>();
//        list.add(ExchangePointsRecordTabFragment.newInstance(true));
//        list.add(ExchangePointsRecordTabFragment.newInstance(false));
        list.add(ExchangePointsRecordTabFragment.newInstance("AD"));
//        list.add(ExchangePointsRecordTabFragment.newInstance("CSC"));
        list.add(ExchangePointsRecordTabFragment.newInstance("积分"));
        return list;
    }

    protected List<String> pagerTitleString() {
        List<String> list = new ArrayList<>();
        list.add("AD记录");
//        list.add("CSC记录");
        list.add("积分记录");
        return list;
    }
}